Skip to content

Conversation

@zacksmash
Copy link
Contributor

@zacksmash zacksmash commented Nov 5, 2025

(resubmitting this from a branch, prev: #95)

This PR aims to tackle a few missing pieces from the MCP Spec, specifically adding meta info to Primitive output, as well as Response output. This is only an initial take on it, if it looks like a good path forward, I'll be happy to continue to refine.

It also includes a complete way to setup the structure for a ChatGPT app, following their SDK specs.

On Primitives Meta:

A new property for $meta was added, which will allow you to attach the _meta output property. Currently, this has only been applied to the Tool output, but may be added to other Primitives. This behaves in the same way that $name, $title or $description would. A new method for securitySchemes() has also been added to tools, which works in a similar fashion to the JSON schema() method.

Example:

#[IsReadOnly()]
class WeatherTool extends Tool
{
    protected array $meta = [
        'someKey' => 'someValue',
        'foo' => 'bar'
    ];

    //  ...
    
    // Or via the meta() method
    
    public function meta(): array
    {
        return [
            'someKey' => 'someValue',
            'foo' => 'bar'
        ]
    }

    public function securitySchemes(SecurityScheme $scheme): array
    {
        return [
            $scheme->oauth2('mcp:use')
        ];
    }

On Tool Response Meta:

A few new fluent methods have been added to the text() response type for meta() and structuredContent(). These are then read in the CallTool method and returned in the response, if they're available.

Example:

#[IsReadOnly()]
class WeatherTool extends Tool
{
    // ...

    /**
     * Handle the tool request.
     */
    public function handle(Request $request, WeatherData $weatherData): Response
    {
        $city = $request->get('city');

        return Response::text("Here is the current weather information you requested for {$city}.")
            ->meta(['route' => 'weather'])
            ->structuredContent($weatherData->handle());
    }

On OpenAI/ChatGPT Apps

A new Response method has been added called app(), to be used in Resource primitives for returning the required data to a ChatGPT app.

Example:

class WeatherAppResource extends Resource
{

    // ...

    /**
     * Handle the resource request.
     */
    public function handle(): Response
    {
        return Response::app(view('mcp.app'),
            fn (App $app) => $app->prefersBorder()
        );
    }

Tip

$app includes some helpers for ChatGPT apps, but also includes a meta() method to allow adding additional items to the metadata response

Summary

This has handled all edge cases for me, in testing locally. The only thing I'm unsure of is if things like Prompts would ever need meta on the primitive level, or on the content level. That can be adjusted very easily, though.

On the topic of ChatGPT Apps, I've also got a fully working app setup, with a separate build process for widgets, that has worked very well, with these changes to the Laravel MCP package. I'd be happy to share it as well -- again, if this is something that looks worthy of moving forward with!

Closes #78

@pushpak1300
Copy link
Member

pushpak1300 commented Nov 6, 2025

Thanks for the PR really solid work. Tests are failing, but could you split this into smaller parts? For example:

  1. Adding meta
  2. Adding structured content
  3. Returning the view in the resource response

That way, it’ll be much easier to review and merge this feature faster.

@zacksmash
Copy link
Contributor Author

zacksmash commented Nov 6, 2025

Thanks for the PR really solid work. Tests are failing, but could you split this into smaller parts? For example:

  1. Adding meta
  2. Adding structured content
  3. Returning the view in the resource response

That way, it’ll be much easier to review and merge this feature faster.

Done! I broke them up a bit differently, but hopefully it's easier to reason with.

  1. Add meta and security scheme to Tool Definiton (Add Meta and Security Schemes to tool definition #101)
  2. Add meta and structured content to Tool Response (Add Meta and Structured Content to tool response #102)
  3. Add App response type, for ChatGPT Apps (Add App response type #103)

This can be closed, if you'd like!

@zacksmash zacksmash marked this pull request as draft November 6, 2025 18:02
@pushpak1300 pushpak1300 closed this Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it simple to build a ChatGPT app

2 participants